<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>改名卡</title>
</head>

<body>
  <div id='app'>
    姓 <input type="text" v-model.trim="firstName"> + 名 <input type="text" v-model.trim="lastName"> =
    <span>{{totalName}}</span>
    <br><br>
    <button @click="changeName">改名卡</button>
  </div>
  <script src="https://cdn.jsdelivr.net/npm/vue@2.7.16/dist/vue.js"></script>
  <script>
    const app = new Vue({
      el: '#app',
      data: {
        firstName: '',
        lastName: ''
      },
      methods: {
        changeName() {
          this.totalName = '世界'
        }
      },
      //使用计算属性完成
      computed: {
        // totalName() {
        //   return this.firstName + this.lastName
        // }
        // 完整写法 获取，设置
        totalName: {
          get() {
            return this.firstName + this.lastName
          },
          set(value) {
            this.firstName = value.slice(0, 1)
            this.lastName = value.slice(1)

          }
        }


      }
    })
  </script>
</body>

</html>